package com.wxyzz.canteenadmin.goods.goodsList.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.goods.goodsList.mapper.GoodsListMapper;
import com.wxyzz.canteenadmin.goods.goodsList.param.GoodsListDataParam;
import com.wxyzz.canteenadmin.goods.goodsList.param.GoodsListVueParam;
import com.wxyzz.canteenadmin.goods.goodsList.service.GoodsListService;
import com.wxyzz.canteencommon.exception.CustmerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsListServiceImpl implements GoodsListService{
    @Resource
    private GoodsListMapper goodsListMapper;
    //查询  展示所有的数据，分页，模糊查询
    @Override
    public PageInfo<GoodsListDataParam> findAllGoodsList(GoodsListVueParam goodsListVueParam) {
        PageHelper.startPage(goodsListVueParam.getPageNum(),goodsListVueParam.getPageSize());
        List<GoodsListDataParam> goodsListDataParams = goodsListMapper.selectAllGoodsList(goodsListVueParam);
        PageInfo<GoodsListDataParam> goodsListDataParamPageInfo = new PageInfo<>(goodsListDataParams);
        return goodsListDataParamPageInfo;
    }
    //添加  添加商品分类信息
    @Override
    public void saveGoodsList(GoodsListVueParam goodsListVueParam) {
        if(goodsListVueParam.getBelongingStoreId()==null){
            throw new CustmerException("请选择所属店铺，所属店铺不能为空！");}
         if(goodsListVueParam.getGoodsName()==null){
             throw new CustmerException("请输入商品名称，商品名称不能为空！");}
        if(goodsListVueParam.getLeaveStock()==null){
            throw new CustmerException("请输入剩余库存，剩余库存不能为空！");}
        if(goodsListVueParam.getGoodsSortId()==null){
            throw new CustmerException("请选择所属菜品分类，所属菜品分类不能为空！");}
        if(goodsListVueParam.getPrice()==null){
            throw new CustmerException("请输入价格，价格不能为空！");}
        if(goodsListVueParam.getUpStatus()==null){
            throw new CustmerException("请选择商品状态，商品状态不能为空！");}
        if(goodsListVueParam.getCreateTime()==null){
            throw new CustmerException("请选择时间，创建时间不能为空！");}
        goodsListMapper.insertGoodsList(goodsListVueParam);
    }
    //修改  在修改前先通过id进行查询展示当前行的信息
    @Override
    public GoodsListDataParam findGoodsListById(int id) {
        GoodsListDataParam goodsListDataParam = goodsListMapper.selectGoodsListById(id);
        return goodsListDataParam;
    }
    //修改  修改商品分类信息
    @Override
    public void UpdateGoodsList(GoodsListVueParam goodsListVueParam) {
        goodsListMapper.UpdateGoodsList(goodsListVueParam);
    }
    //删除  根据当前行的Id删除
    @Override
    public void deleteGoodsListById(int id) {
        goodsListMapper.deleteGoodsListById(id);
    }
    //删除 批量删除
    @Override
    public void delBatchGoodsListById(List<Integer> ids) {
        goodsListMapper.delBatchGoodsListById(ids);
    }
}
